<!DOCTYPE html>
<html>
<head>
<title>用户维护页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
	    var path = window.document.location.href;
		var pathName = window.document.location.pathname;
		var hostPath = path.substring(0, path.indexOf(pathName));
		var projectName = pathName.substring(0, pathName.substr(1).indexOf("/") + 1);
		document.write('<scr' + 'ipt src="' + projectName + '/js/html/header.js"></scr'+'ipt>');
    </script>
</head>
<body>
	<table id="dg" style="width: auto; height: auto">
		<thead>
			<tr>
				<th field="id" data-options="hidden:true">ID</th>
				<th field="loginName" width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">登录用户号</th>
				<th field="userName" width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">用户姓名</th>
				<th field="empNo" width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">员工号</th>
				<th field="orgId" width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">机构</th>
				<th field="status" width="100" align="right"
					data-options="
					sortable:true,
					remoteSort:false,
					editor:{
						type:'validatebox',
						options:{
							required:true
						}
					}">状态</th>

			</tr>
		</thead>
	</table>
	<div id="dg-buttons" style="height: auto">
		<div style="margin-bottom:5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" 	onclick="dlgAdd()">新增</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" 	onclick="removeUser()">删除</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" 	onclick="dlgEdit()">修改</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-excel',plain:true" 	onclick="dlgExport()">导出</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reset',plain:true" 	onclick="resetPwd()">密码重置</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-unlock',plain:true" 	    onclick="unlockUser()">解锁</a>
		</div>
		<div>
			<span>用户姓名:</span>
			<input type="text" id="userName" name="userName" class="easyui-validatebox" />
			<span>员工号:</span>
			<input type="text" id="empNo" name="empNo" class="easyui-validatebox" />
			<span>机构:</span>
			<input type="text" id="orgId" name="orgId" class="easyui-validatebox" />
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="dgop.find()">查询</a>
		</div>
	</div>

	<div id="dlg-buttons">
		<a href="javascript:dlgSave()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a href="javascript:dlgClose()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>

	<div id="dlg" class="easyui-dialog" closed="true" style="width: 730px; height: 280px; padding: 10px 10px;" buttons="#dlg-buttons">
		<form method="post" id="fm">
			<table cellspacing="8px;">
				<td><input id="id" name="id" style="display: none" required="true"></td>
				<tr>
					<td>登录用户号：</td>
					<td><input type="text" id="loginName" name="loginName" class="easyui-validatebox" required="true">&nbsp; <span style="color: red">*</span></td>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
					<td>用户姓名：</td>
					<td><input type="text" id="userName" name="userName" class="easyui-validatebox" required="true" />&nbsp; <span style="color: red">*</span></td>
				 </tr>
				<tr>
				    <td>员工号：</td>
				    	<td><input type="text" id="empNo" name="empNo" class="easyui-validatebox" required="true" />&nbsp; <span style="color: red">*</span></td>
			        <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
					<td>机构：</td>
					<td><input type="text" id="orgId" name="orgId" class="easyui-combobox" required="true" />&nbsp; <span style="color: red">*</span></td>
				</tr>
				<tr>
			        <td>状态：</td>
					<td><input type="text" id="status" name="status" class="easyui-combobox" required="true" />&nbsp; <span style="color: red">*</span></td>
		    	</tr>
			</table>
		</form>
	</div>



	<script>
		var initd = {
			queryDataURL:"/system/userinfo/query",//查询URL
			saveDataURL:"/system/userinfo/save",//保存URL
			dg:$('#dg'),
			dataDicList:{'ORG':['orgId'],'1':['status']}//需加载的 DATADIC 字典名+作用的字段名
		};

        function removeUser() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的数据！");
                return;
            }
            var removeData = selectedRows[0]
            if (selectedRows.length > 1) {
                removeData = {
                    'deleteRows':deleteRows,
                }
            }

            var loginName = removeData.loginName;
            
            $.messager.confirm("系统提示", "您确定要删除此用户吗？建议将用户置为无效。", function(r) {
                if (r) {
                    $.ajax({
                        type:"DELETE",
                        dataType:"json",
                        url : projectName+"/system/userinfo/"+loginName+"/remove",
                        beforeSend : function() {
                        },
                        success : function(result) {
                            if (result.success) {
                                $.messager.alert("系统提示", "数据已成功删除！");
                                $("#dg").datagrid("reload");
                            } else {
                                if(!jQuery.isEmptyObject(result.message)){
                                    $.messager.alert("系统错误", result.message);
                                }else{
                                    $.messager.alert("系统错误", result);
                                }
                                return;
                            }
                        },
                        error:function(err, status){
                            errorMsgAlert(err);
                            $.messager.progress("close");
                        }
                    });

                }
            });
        }

		
		function resetPwd() {
			if(editRow != undefined){
				initd.dg.datagrid('endEdit',editRow);
			}
			var rows = initd.dg.datagrid('getSelections');
			if(rows.length == 1){
                var loginName = rows[0].loginName;
                
				$.ajax({
					type : "POST",
					url : projectName+"/system/userinfo/"+loginName+"/reset",						
					data : {
						'id' : rows[0].id,
						'userName' : rows[0].userName
					},
					dataType : "json",
					success : function(data) {
						if (!data.success) {
							alert(data.message);
							return;
						}
						if (data != null) {
							initd.dg.datagrid('reload');
							$.messager.alert('提示','密码已重置为[88888888]');
						}
					}
				});
					
			}
		}
		
		
		function unlockUser() {
			if(editRow != undefined){
				initd.dg.datagrid('endEdit',editRow);
			}
			var rows = initd.dg.datagrid('getSelections');
			if(rows.length == 1){
                var loginName = rows[0].loginName;

				$.ajax({
					type : "POST",
					url : projectName+"/system/userinfo/"+loginName+"/unlock",						
					data : {
						'id' : rows[0].id,
						'userName' : rows[0].userName
					},
					dataType : "json",
					success : function(data) {
						if (!data.success) {
							alert(data.message);
							return;
						}
						if (data != null) {
							initd.dg.datagrid('reload');
							$.messager.alert('提示','用户解锁成功');
						}
					}
				});
					
			}
		}
		
	</script>
</body>
</html>

